package com.cj.wtrails.http;

import android.app.Activity;

import androidx.fragment.app.Fragment;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * 工具类 获取网络数据 json
 *
 * @author zengyi
 * create at 2016/9/20 9:27
 */

public class HttpRequest {


    public static <T> void execute(Activity activity, Observable<T> observable, Observer<T> observer) {

        observable.subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread(), true)
                //.compose(RxUtils.bindToLifecycle(activity))
                .subscribe(observer);

    }

    public static <T> void execute(Fragment fragment, Observable<T> observable, Observer<T> observer) {

        observable.subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread(), true)
                //.compose(RxUtils.bindToLifecycle(fragment))
                .subscribe(observer);

    }


}